export default {
  name: 'HeadNav',
  data () {
  	 return {
			nav:[
				{
						text:'计划管理',
						url:'/planList'
				},
				{
						text:'创意管理',
						url:'/creativity'
				}  
			],
			options:[],
			shop:'',
			oldshop:''
		}
	},
  	computed: {
		users(){
			return this.$store.getters.users
		},
		selectShop_key(){
			return this.$store.getters.selectShop_key
		},
		headerNavActive(){
			return this.$store.getters.headerNavActive
		},
		active(){
			return this.headerNavActive
		}
	},
	mounted() {
		if(this.users){
			this.getShops();
		}
		this.$store.commit('setHeaderNavActive','计划管理');
	},
  	methods:{
		toPage(obj){
			this.$store.commit('setHeaderNavActive',obj.text);
			this.$router.push(obj.url);
		},
		signOut(){
			this.$http({
				method:'post',
				url:'/site/logout'
			}).then((data) => {
				if (!this.$http.interceptors(this, data)) return;
				this.$store.commit('signOut');
				this.$router.push('/login');
			})
			.catch(function (error) {
				console.log(error);
			});
		},
		getShops(){
			this.$http({
				method: 'get',
				url:'/zuanzhan/shops'
			}).then((data) => {
				// if (!this.$http.interceptors(this, data)) return;
					this.options=data.data.data;
					if(this.selectShop_key){
						this.shop=this.selectShop_key;
						this.oldshop=this.selectShop_key;
					}else{
						this.shop=this.options[0].shop_key;
						this.oldshop=this.options[0].shop_key;
					}
			})
			.catch(function (error) {
				console.log(error);
			});
		},
		slectChange(val){
			    let _this=this;
			    let obj={
			 		shop_key:val
			 	}
				this.$http({
					method: 'post',
					url: '/zuanzhan/shop/change',
					data:obj,
				}).then((data) => {
					//if (!this.$http.interceptors(this, data)) return;
					this.$store.commit('setSelectShop_key',val);
			 		this.oldshop=val;
			 		window.location.reload();
				})
				.catch(function (error) {
					console.log(error);
				});
		}
  }
}